package condionals;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.HashMap;
import java.util.Map;

public class ClassCondition implements Condition
{
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map<String,Object>  attributes=metadata.getAnnotationAttributes(ConditionClasss.class.getName());
     Object   value= attributes.get("className");
     if (value!=null){
         String className=value.toString();
         try {
             context.getClassLoader().loadClass(className);
         } catch (ClassNotFoundException e) {
           return false;
         }
     }
        return true;
    }
}
